package com.cqc.googleplay.adapter;

import java.util.List;

import com.cqc.googleplay.R;
import com.cqc.googleplay.application.ImageLoaderOptions;
import com.cqc.googleplay.bean.ImageInfoBean;
import com.cqc.googleplay.http.NetUrl;
import com.cqc.googleplay.view.RatioImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class SubjectFragAdapter extends BaseListAdapter<ImageInfoBean> {

	public SubjectFragAdapter(List<ImageInfoBean> list) {
		super(list);	
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder ;
		if (convertView == null) {
			convertView = View.inflate(parent.getContext(), R.layout.item_subject_frag, null);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		ImageInfoBean info = list.get(position);
		ImageLoader.getInstance().displayImage(NetUrl.IMAGE_PREFIX+ info.getUrl(), holder.iv, ImageLoaderOptions.options);
		holder.tv.setText(""+info.getDes());
		return convertView;
	}
	
	public class ViewHolder {

//		public ImageView iv;
		public RatioImageView iv;
		public TextView tv;

		public ViewHolder(View itemView) {
			super();
//			iv = (ImageView) itemView.findViewById(R.id.iv_subject_farg);
			iv = (RatioImageView) itemView.findViewById(R.id.iv_subject_farg);
			
			tv = (TextView) itemView.findViewById(R.id.tv_subject_farg);
		}		
	}
}
